﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using DBControl;

namespace Newsell
{
    public partial class mycate : TopBasePage
    {
        string sql;
        string action;
        protected void Page_Load(object sender, EventArgs e)
        {
            action = Request.QueryString["act"].ToString();

            if (!IsPostBack)
            {
                bindRepeater();
                getTotalCount();
            }
        }
        /// <summary>
        /// 绑定买家需求数据
        /// </summary>
        private void bindRepeater()
        {
            ITopControl iinit = new ITopControl();
            SqlDbHelper sdh = new SqlDbHelper();
            long curCid = 0;
            string sqlwhere = "";
            string sqlcid = "";

            curCid = iinit.shopCatGet(Session["usNick"].ToString());
            if (curCid != 0)
            {
                sqlcid = "[Parentcateid]=" + curCid;
            }
            else { jsargs.AlertAndRedirect("类目出错！", "sell404.htm", this.Page); }

            if (action == "0")//判断动作，0 = 未发布
            {
                sqlwhere = " where " + sqlcid + " and [Status]=0 and [bsc]=0 or " + sqlcid + " and [Status]=0 and [bsc]<>0 and [rsn] <> '" + Session["usNick"].ToString() + "'";
            }
            else if (action == "1")
            { 
                sqlwhere = " where " + sqlcid + " and [Status] = 0 and [rsn] = '" + Session["usNick"].ToString() + "'";
            }


                //sqlwhere = " where [Status]=0 and [bsc]=0 or [Status]=0 and [bsc]<>0 and [rsn] <> '" + Session["usNick"].ToString() + "'";
            if (sqlwhere != "")
            {
                sql = sqlwhere;
            }
            else { sql = ""; }
            SqlParameter p1 = new SqlParameter("@tablename", "GetDateByUser");//视图名或表名
            SqlParameter p2 = new SqlParameter("@pagerow", this.listupPager.PageSize);         //每页显示记录数 
            SqlParameter p3 = new SqlParameter("@pagenow", this.listupPager.CurrentPageIndex); //当前显示第几页 
            SqlParameter p4 = new SqlParameter("@ordercol", "Starttime");//排序字段
            SqlParameter p5 = new SqlParameter("@order", 1);//排序顺序，0升序，1降序
            SqlParameter p6 = new SqlParameter("@where", sqlwhere);
            SqlParameter[] paras = new SqlParameter[] { p1, p2, p3, p4, p5, p6 };
            this.RepSellMain.DataSource = sdh.ExecuteDataTable("sp_page", System.Data.CommandType.StoredProcedure, null, paras);
            RepSellMain.DataBind();
        }
        /// <summary>
        /// 获得买家需求总数，分页使用
        /// </summary>
        private void getTotalCount()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlcount = "SELECT COUNT(*) FROM GetDateByUser" + sql;
            this.listupPager.RecordCount = int.Parse(sdh.ExecuteScalar(sqlcount).ToString());
        }
        /// <summary>
        /// 翻页，此处需要绑定要执行的js函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void listupPager_PageChanged(object sender, EventArgs e)
        {
            bindRepeater();
            execStartupjs();
        }

        /// <summary>
        /// 执行js函数
        /// </summary>
        protected void execStartupjs()
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "documentready", "<script>ResizeImg();infoDeCode();slideDetail();goodContToggle();</script>", false);
        }
    }
}